import os
import package.GUI_set as gs
import package.sql_command_set as scs
# 定义函数用于选择文件类型
def select_file_type():
    # 定义选项
    options_list = ["招商信用卡未出账","招商信用卡已出账","招商储蓄卡","浦发储蓄卡","中信信用卡已出账","宁波储蓄卡"]
    # 调用函数select_option并传入选项调用函数，获取用户选择的值
    selected_value = gs.select_option(options_list,False)
    path = f"{selected_value}\\"
    # 获取路径path下的所有文件
    files_list = os.listdir(path)
    # 获取所有文件路径
    file_paths = [str(os.path.join(path, file)).strip() for file in files_list]
    return file_paths

# 定义函数用于获取mysql数据库中的账户
def get_accounts():
    connection, status = scs.create_database_connection("localhost", "root", "123456", "beancount")
    print(status)
    account_list = scs.sql_select(connection,"select * from account")
    scs.close_database_connection(connection)
    Assets_list =[] 
    Expenses_list = []
    Equity_list =  []
    Income_list = []
    Liabilities_list = []
    for row in account_list:
        if "Assets" in str(row[0]):
            Assets_list.append(str(row[1]).strip())
        elif "Expenses" in str(row[0]):
            Expenses_list.append(str(row[1]).strip())
        elif "Equity" in str(row[0]):
            Equity_list.append(str(row[1]).strip())
        elif "Income" in str(row[0]):
            Income_list.append(str(row[1]).strip())
        elif "Liabilities" in str(row[0]):
            Liabilities_list.append(str(row[1]).strip())
    return Assets_list,Expenses_list,Equity_list,Income_list,Liabilities_list
# 定义函数用于选择账户
def select_account():
    Assets_list,Expenses_list,Equity_list,Income_list,Liabilities_list=get_accounts()
    options_list = ["资产","支出","平衡","收入","负债"]
    selected = gs.select_option(options_list,False)
    if selected == "资产":
        return gs.select_option(Assets_list,False)
    elif selected == "支出":
        return gs.select_option(Expenses_list,False)
    elif selected == "平衡":
        return gs.select_option(Equity_list,False)
    elif selected == "收入":
        return gs.select_option(Income_list,False)
    elif selected == "负债":
        return gs.select_option(Liabilities_list,False)

# 测试函数
if __name__ == '__main__':
    print(select_account())